home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11815 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.3 KB  |  44 lines

  1. Path: inforamp.net!ts14-03
  2. From: rmorin@inforamp.net (Randy Charles Morin)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: overloading ->
  5. Date: Sat, 16 Mar 96 09:38:27 GMT
  6. Organization: MiddleWorld SoftWare
  7. Message-ID: <4ie274$pc1@sam.inforamp.net>
  8. References: <4id6o2$t5n@vixen.cso.uiuc.edu>
  9. NNTP-Posting-Host: ts14-03.tor.inforamp.net
  10. X-Newsreader: News Xpress Version 1.0 Beta #4
  11.  
  12. In article <4id6o2$t5n@vixen.cso.uiuc.edu>,
  13.    wemccaug@prairienet.org (Wendy E. McCaughrin) wrote:
  14. > I realize that in addition to returning an object pointer
  15. > as value, a member operator -> can also return an object,
  16. > but I am wondering if there is a way to overload it so it
  17. > can return two different pointer types directly. My problem
  18. > is that it has to be a member operator taking no arguments,
  19. > so the different return-values would be the only distinction
  20. > and, of course, that is not enough to make them regarded as
  21. > different by the compiler. Any suggestions?
  22.  
  23. Here's what I'm thinking.  You have a primary class member function that 
  24. returns a secondary class.  The secondary class has built-in implicit type 
  25. conversion routines that pass one value when converting to type x and another 
  26. when converting to type y.
  27.  
  28. class Primary
  29. {
  30. public:
  31.     Secondary get(){Secondary s; s.i=0; s.c=0; return s;};
  32. };
  33.  
  34. class Secondary
  35. {
  36. public:
  37.     int i;
  38.     char c;
  39. };
  40.  
  41. Get the idea.
  42.  
  43. Agrivar
  44.